package com.hmy.infrastructure.client.signature;

import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.common.result.Results;
import com.hmy.ccp.error.annotations.HmyFeignController;
import com.hmy.infrastructure.bo.request.signature.*;
import com.hmy.infrastructure.bo.response.signature.*;
import com.hmy.infrastructure.service.signature.ISignatureService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author seven.qi 齐胜南
 * @version 1.0
 * @description 电子签名feign客户端
 * @date 2023/12/20 16:25
 */

@Slf4j
@Api(tags = "电子签名feign客户端")
@RestController("feignSignatureClientController")
@Validated
@HmyFeignController
public class SignatureClientController {

    @Resource
    private ISignatureService signatureService;

    @PostMapping("/feign/signature/create")
    @ApiOperation("创建电子签约流程")
    public FeignResult<CreateSignatureProcessResponse> create(@RequestBody CreateSignatureProcessRequest createSignatureProcessRequest) {
        return Results.newSuccessResult(signatureService.create(createSignatureProcessRequest));
    }

    @PostMapping("/feign/signature/createContract")
    @ApiOperation("创建电子签约流程")
    public FeignResult<CreateContractResponse> createContract(@RequestBody CreateContractRequest createContractRequest) {
        return Results.newSuccessResult(signatureService.createContract(createContractRequest));
    }

    @PostMapping("/feign/signature/signTemplateFieldFill")
    @ApiOperation("签约模板数据填充")
    public FeignResult<SignTemplateFieldFillResponse> signTemplateFieldFill(@RequestBody SignTemplateFieldFillRequest fieldFillRequest) {
        return Results.newSuccessResult(signatureService.signTemplateFieldFill(fieldFillRequest));
    }

    @PostMapping("/feign/signature/fileTemplateFieldFill")
    @ApiOperation("文件模板数据填充")
    public FeignResult<FileTemplateFieldFillResponse> fileTemplateFieldFill(@RequestBody FileTemplateFieldFillRequest fileTemplateFieldFillRequest) {
        return Results.newSuccessResult(signatureService.fileTemplateFieldFill(fileTemplateFieldFillRequest));
    }

    @PostMapping("/feign/signature/start")
    @ApiOperation("开始签约流程")
    public FeignResult<StartSignatureProcessResponse> start(@RequestBody StartSignatureProcessRequest startSignatureProcessRequest) {
        return Results.newSuccessResult(signatureService.start(startSignatureProcessRequest));
    }

    @PostMapping("/feign/signature/getSignFileUrl")
    @ApiOperation("获取签署完成后的文件链接")
    public FeignResult<GetSignFileUrlResponse> getSignFileUrl(@RequestBody GetSignFileUrlRequest getSignFileUrlRequest) {
        return Results.newSuccessResult(signatureService.getSignFileUrl(getSignFileUrlRequest));
    }

    @PostMapping("/feign/signature/getSignTaskUrl")
    @ApiOperation("获取签约链接")
    public FeignResult<GetSignTaskUrlResponse> getSignTaskUrl(@RequestBody GetSignTaskUrlRequest getSignTaskUrlRequest) {
        return Results.newSuccessResult(signatureService.getSignTaskUrl(getSignTaskUrlRequest));
    }

    @PostMapping("/feign/signature/createContractByFile")
    @ApiOperation("通过文件创建合同")
    public FeignResult<CreateContractByFileResponse> createContractByFile(@RequestBody CreateContractByFileRequest createContractRequest) {
        return Results.newSuccessResult(signatureService.createContractByFile(createContractRequest));
    }

    @PostMapping("/feign/signature/cancel")
    @ApiOperation("撤销合同")
    public FeignResult<SignTaskCancelResponse> cancel(@RequestBody SignTaskCancelRequest request) {
        return Results.newSuccessResult(signatureService.signTaskCancel(request));
    }


}
